using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Interface;
using Spinning.Spinning.Entity;
using Spinning.Spinning.Entity.Particle;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Level
{
    class ParticleShoter : IUpdateHandler
    {
        IParticle bullet;
        PracticeScene _scene;
        float velo;

        public ParticleShoter(PracticeScene scene)
            : base()
        {
            this._scene = scene;
            Marble m = new Marble();
            m.textureName = "marble";
            m.OnLoad();
           // marble.Style = 1;
            m.SetAnimation(new Point(1, 1),new int[] {0});
            m.OnCreatBody(_scene.World, _scene.PhysicConnectManager);
            m.BodyPosiotion = new Vector2(-2000 , -2000);
           // marble.OnBeginContactEvent += onParticleContact;
            _scene.Attach(m);
            bullet = m;
            velo = 65;
        }

        public void Shot(Vector2 target) {
            Vector2 pos=_scene.Player.Position;
            Vector2 dec=target-pos;
            dec.Normalize();
            if (!bullet.isDead)
                ShotParticle(bullet,pos,dec);
        }

        protected void ShotParticle(IParticle particle,Vector2 pos,Vector2 dec) {
                particle.Reset();
                particle.ParticlePosition = pos;
                particle.Velocity = dec * velo;
        }

        public void OnUpdate(Microsoft.Xna.Framework.GameTime gameTime)
        {
            if (bullet.isDead) {
                bullet.Reset();
                bullet.ParticlePosition = new Vector2(-2000);
            }
        }
    }
}
